$(document).ready(function() {
    adjustImgs();
})
function adjustImgs() {
    $('.fakecrop').each(function() {
        var self = $(this);
        var img = new Image();
        img.src = self.find('img').attr('src');
        img.addEventListener('load' , function() {
            var imgWidth = img.width;
            var imgHeight = img.height;

            if ((imgWidth / imgHeight) >= (self.width() / self.height())) {
                self.find('img').css({ "width": "100%", "height": "auto" });
            } else {
                self.find('img').css({ "width": "auto", "height": "100%" });
            }
        }, false);
    })
    $('.fillimg').each(function() {
        var self = $(this);
        var img = new Image();
        img.src = self.find('img').attr('src');
        img.addEventListener('load' , function() {
            var imgWidth = img.width;
            var imgHeight = img.height;

            /*if (imgWidth <= imgHeight) {
                self.find('img').css({ "width": "100%", "height": "auto" });
            } else if ((imgWidth * (self.height() / imgHeight)) <= self.width()) {
                self.find('img').css({ "width": "100%", "height": "auto" });
            } else {
                self.find('img').css({ "width": "auto", "height": "100%" });
            }*/
            if ((imgWidth / imgHeight) >= (self.width() / self.height())) {
                self.find('img').css({ "width": "auto", "height": "100%" });
            } else {
                self.find('img').css({ "width": "100%", "height": "auto" });
            }
        }, false);
    })
}